package com.cnc.dao;

import com.cnc.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Select("select * from user where uid=#{id}")
    User getUserById(@Param("id") int id);

    @Select("select * from user where name like (concat('%',#{search},'%')) limit #{off},#{len};")
    List<User> getAdminList(@Param("off") int off, @Param("len") int len , @Param("search") String search);

    @Select("select count(*) from user where name like (concat('%',#{search},'%'))")
    int getRows(@Param("search") String search);

    @Select("select uid from user where username=#{username} and password=#{password};")
    Object Login(@Param("username") String username,@Param("password") String password);

    @Select("select status from user where uid=#{id}")
    int getStatus(@Param("id") int id);

    @Select("select role from user where uid=#{id}")
    int getRoles(@Param("id") int id);

    @Update("update user set name=#{u.name},phone=#{u.phone},age=#{u.age},sex=#{u.sex},username=#{u.username},password=#{u.password},status=#{u.status},createtime=#{u.createtime},role=#{u.role},picture=#{u.picture} where uid=#{u.uid}")
    int updateUser(@Param("u")User u);

    @Insert("insert into user(name,phone,age,sex,username,password,status,createtime,role,picture) values(#{u.name},#{u.phone},#{u.age},#{u.sex},#{u.username},#{u.password},#{u.status},#{u.createtime},#{u.role},#{u.picture})")
    int addUser(@Param("u")User u);

    @Delete("delete from user where uid=#{uid}")
    int delUserById(@Param("uid")int id);

    @Select("select count(*) from user where phone=#{phone}")
    int checkPhone(@Param("phone")String phone);

    @Select("select * from user where phone=#{phone} and password=#{password}")
    User userLogin(@Param("phone") String phone,@Param("password") String password);
}
